package com.xinqing.test.algorithm.k8s.forecast;

import com.alibaba.fastjson.JSON;
import com.feidee.fdcommon.authorization.AuthorizationVerify;
import com.feidee.fdcommon.authorization.model.AuthInfoModel;
import com.feidee.fdcommon.configuration.CustomConfiguration;
import com.feidee.fdcommon.model.StringResponse;
import com.feidee.fdcommon.util.HttpUtil;
import com.xinqing.test.modle.algorithm.ForecastParam;
import org.apache.http.Consts;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author:CHQ
 * @Date:2020/9/29 17:03
 * @Description
 */
public class ST49e03f0c1f993a2c {
    public static void main(String args[]) throws Exception {
        Date d = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = sdf.format(d);


    /*   String data="{\"busId\":\"ad_ctr\"," +
                "\"features\":{\"n1\":\"1\",\"n2\":\"5\",\"n3\":\"11\",\"n4\":\"0\",\"n5\":\"0\",\"n6\":\"2\",\"n7\":\"9\",\"n8\":\"11\"," +
                "\"n9\":\"0\",\"u31\":\"1\",\"us1\":\"1\",\"us0\":\"68\",\"us3\":\"6000\",\"t1\":\"2020-09-29 17:23:27\"}," +
                "\"models\":[\"693ba772fab3a1d8\",\"951c327c56779183\"]," +
                "\"multiFeatures\":{\"97516\":{\"u32\":\"1\",\"us2\":\"0.0147\",\"us4\":\"57\",\"u37\":\"0\",\"u36\":\"0\",\"u39\":\"1\",\"u17\":\"0\",\"u38\":\"249\"}," +
                "\"top\":\"0\","+
                "\"traceId\":\"990a790a29f9e8e1d6335693ebd8a70639ba691ef4735c761554171a6fed822afcfe3475eb3dce68f890e69d73268796\"}";*/

        ForecastParam forecastParam = new ForecastParam();
        forecastParam.setBusId("ad_wdl");


        Map<String, Object> featuresMap = new HashMap<>();
        featuresMap.put("channelsys","MyMoney");
        featuresMap.put("devssj_click_daynum_7d","0");
        featuresMap.put("devssj_sp_clk_30d","0");
        featuresMap.put("devssj_ssj_inactive_days","1");
        featuresMap.put("userssj_jr_trade_system_90d","other");
        featuresMap.put("userssj_is_tra_cost","0");
        featuresMap.put("accountid","35");
        featuresMap.put("userssj_ssj_activedays_7d","7");
        featuresMap.put("devssj_device_channel","huawei");
        featuresMap.put("model","COL-AL10");
        featuresMap.put("devssj_ssj_install_con_daikuan","1");
        featuresMap.put("devssj_ssjsyyyw_last_show_gap_day","0");
        featuresMap.put("userssj_yx_ssj_showzbtt_30d","0");
        featuresMap.put("devssj_ssjd_load_seeapp_num","0");
        featuresMap.put("devssj_account_shownum_7d","{\"35\":6, \"98\":5, \"10\":4, \"100\":2}");
        featuresMap.put("userssj_sq_user","1");
        featuresMap.put("userssj_ssj_usual_province_180d","甘肃");
        featuresMap.put("groupname","SSJ_CVR_MODEL_DJ");
        featuresMap.put("userssj_ssj_regular_income_true","1");
        featuresMap.put("devssj_origid_shownum_7d","{\"41364\":3, \"8639\":2, \"8638\":2, \"42745\":2, \"42539\":2, \"12099\":2, \"9739\":1, \"42544\":1, \"41358\":1, \"10374\":1}");
        featuresMap.put("userssj_yx_ssj_showxxt_30d","0");
        featuresMap.put("size","0.56");
        featuresMap.put("devssj_app_max_score","1");
        featuresMap.put("devssj_ssj_install_con_p2p","1");
        featuresMap.put("devssj_acitve_channel_type","其他正常渠道");
        featuresMap.put("userssj_is_cib","0");
        featuresMap.put("planid","95416");
        featuresMap.put("devssj_mostprovince_180d","甘肃");
        featuresMap.put("userssj_ssj_asset_level","3");
        featuresMap.put("devssj_is_visitfin_maxdate","2020-02-13");
        featuresMap.put("devssj_jr_debt_is_update","1");
        featuresMap.put("devssj_activedays_7d","7");
        featuresMap.put("devssj_t_pdtname","MyMoney For Huawei");
        featuresMap.put("userssj_is_fengjin_whitelist","1");
        featuresMap.put("devssj_is_sms_sign","1");
        featuresMap.put("userssj_yx_ssj_clickzbtt_30d","0");
        featuresMap.put("userssj_yx_ssj_recivemes_30d","6");
        featuresMap.put("devssj_app_q3_num","21");
        featuresMap.put("userssj_sq_is_visit_7d","0");
        featuresMap.put("devssj_click_positionnum_7d","0");
        featuresMap.put("userssj_ssj_system","android OS");
        featuresMap.put("devssj_d_activedays","755");
        featuresMap.put("positionid","SSJSYYYW");
        featuresMap.put("userssj_ssj_sp_explastday_30d","1");
        featuresMap.put("userssj_is_ec_cost","0");
        featuresMap.put("userssj_ssj_credit","1");
        featuresMap.put("userssj_ssj_pv30d","4063");
        featuresMap.put("userssj_ssj_no_income_user","1");
        featuresMap.put("devssj_click_requestnum_7d","0");
        featuresMap.put("devssj_latestcity_180d","兰州");
        featuresMap.put("devssj_ssjd_load_app_num","0");
        featuresMap.put("systemversion","10");
        featuresMap.put("userssj_fn_registered_channel","huawei");
        featuresMap.put("userssj_ssj_transdays_7d","7");
        featuresMap.put("systemname","Android");
        featuresMap.put("userssj_jr_intime_finpage_times","2");
        featuresMap.put("devssj_click_busitypenum_7d","0");
        featuresMap.put("userssj_ssj_bzbook_no","4");
        featuresMap.put("userssj_logon_7days","1");
        featuresMap.put("devssj_origid_clicknum_7d","");
        featuresMap.put("devssj_app_q1_num","0");
        featuresMap.put("userssj_is_cncb","0");
        featuresMap.put("partner","huawei");
        featuresMap.put("devssj_sp_last_show_gap_day","0");
        featuresMap.put("devssj_sp_same_origid_didnot_click_num","1");
        featuresMap.put("devssj_sp_didnot_click_num","34");
        featuresMap.put("userssj_if_businessentity","1");
        featuresMap.put("userssj_zq_fin_user","0");
        featuresMap.put("devssj_is_savejyb_1d","1");
        featuresMap.put("devssj_ms_clk_fn_30d","0");
        featuresMap.put("userssj_openapp_peakhours","16");
        featuresMap.put("userssj_ssj_transdays_30d","30");
        featuresMap.put("devssj_ssjsyyyw_same_origid_didnot_click_num","1");
        featuresMap.put("userssj_ssj_regular_income","1");
        featuresMap.put("devssj_app_low_score_num","0");
        featuresMap.put("devssj_sp_last_click_gap_day","9");
        featuresMap.put("devssj_is_student","0");
        featuresMap.put("devssj_click_shopnum_7d","0");
        featuresMap.put("devssj_stock_app_instl","0");
        featuresMap.put("devssj_jz_history_sum_count","8101");
        featuresMap.put("userssj_ssj_is_click_jyb_1d","1");
        featuresMap.put("userssj_jr_fb_visittimes_7days","1");
        featuresMap.put("devssj_dno","2");
        featuresMap.put("userssj_ssj_operator_from_phone","中国联通网络");
        featuresMap.put("userssj_jiyibino_30d","297");
        featuresMap.put("devssj_ssjsyyyw_didnot_click_num","19");
        featuresMap.put("userssj_is_bcom","0");
        featuresMap.put("userssj_fd_in_apply_page_time","null");
        featuresMap.put("devssj_ssj_install_con_baoxian","0");
        featuresMap.put("viewtime","2020-09-04 00:01:43");
        featuresMap.put("groupid","0");
        featuresMap.put("userssj_ssjd_transtitle","1");
        featuresMap.put("devssj_is_clickjyb_1d","1");
        featuresMap.put("userssj_ssj_partner","huawei");
        featuresMap.put("userssj_jzgame_amount","313");
        featuresMap.put("devssj_app_min_score","17");
        featuresMap.put("devssj_activedays_30d","30");
        featuresMap.put("devssj_is_operation_actday","0");
        featuresMap.put("userssj_is_cmb","0");
        featuresMap.put("devssj_app_average_score","4");
        featuresMap.put("devssj_ins_ms_click_30d","0");
        featuresMap.put("devssj_ssj_opendays_30d","31");
        featuresMap.put("productversion","12.69.0.0");
        featuresMap.put("devssj_ssj_install_con_banka","2");
        featuresMap.put("userssj_is_spd","0");
        featuresMap.put("devssj_ssj_install_con_fin","2");
        featuresMap.put("devssj_predict_sex","1");
        featuresMap.put("devssj_ssjsyyyw_last_click_gap_day","11");
        featuresMap.put("devssj_credit_ms_click_30d","0");
        featuresMap.put("devssj_ssjd_load_gameapp_num","0");
        featuresMap.put("userssj_ssj_is_trans_register_0m","1");
        featuresMap.put("business_type","sfunction");
        featuresMap.put("productname","MyMoney");
        featuresMap.put("userssj_ssj_is_save_jiyibi_1d","1");
        featuresMap.put("userssj_yx_ssj_clickxxt_30d","0");
        featuresMap.put("devssj_createtime","2018-08-10 00:00:00");
        featuresMap.put("userssj_jr_number_coupon","0");
        featuresMap.put("devssj_ms_clk_30d","0");
        featuresMap.put("userssj_zq_card_user","0");
        featuresMap.put("devssj_show_times_monthly","253");
        featuresMap.put("devssj_click_spnum_7d","0");
        featuresMap.put("product_type","saccount");
        featuresMap.put("devssj_ssfl_ms_reh_30d","0");
        featuresMap.put("userssj_is_cgb","0");
        featuresMap.put("devssj_device_active_time","2018-08-10 18:59:42");
        featuresMap.put("userssj_jzc_30d_amt_level","7");
        featuresMap.put("devssj_is_click_7d","0");
        featuresMap.put("goods_type","GOODS-1273896426438393856");
        featuresMap.put("origid","41974");

        forecastParam.setFeatures(featuresMap);
       // "\"multiFeatures\":{\"97516\":{\"u32\":\"1\",\"us2\":\"0.0147\",\"us4\":\"57\",\"u37\":\"0\",\"u36\":\"0\",\"u39\":\"1\",
        // \"u17\":\"0\",\"u38\":\"249\"}," +
        HashMap<String, Map<String, Object>> multiFeaturesMap = new HashMap<>();
        HashMap<String, Object> map = new HashMap<>();
    /*    map.put("c3","98");
        map.put("c4","0");
        map.put("c7","SSJSYYYW");
        map.put("c0","42539");*/
       // multiFeaturesMap.put("96544",map);
      //  forecastParam.setMultiFeatures(multiFeaturesMap);
        //"\"models\":[\"693ba772fab3a1d8\",\"951c327c56779183\"]," +
    //    forecastParam.setModels(new String[]{"aa1435d0024cacf1","1d17ee93a0132f02"});
        forecastParam.setModels(new String[]{"f8123c6d4772c81c"});
        forecastParam.setTop(0);

        String data = JSON.toJSONString(forecastParam);

        //分配的AccessKeyId
        String accessKeyId = "data_team";
        //分配的AccessSecret
        String accessSecret = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJ6+UYiQtt2OYfyfBF8e12kjd6nnF0Zl1s23f7l+eSl07xQxoxACSXyO3aq/tF7g0IiQZev4SF7ZA/oAOIYlYo0CAwEAAQ==";

       // String url = "http://10.201.7.239:8063/sml/forecast/realTimes";
        String url = "https://sml.suishoudata.com/model/49e03f0c1f993a2c";

        //调用鉴权工具包计算鉴权信息,data不存则传空
        AuthInfoModel authInfo = AuthorizationVerify.getAuthInfo(url, data, accessKeyId, accessSecret);
        //获取GMT时间+
        String date = authInfo.getDate();
        //获取加密之后的data，若传入data为空，则密文也为空
        String ciphertext = authInfo.getCiphertext();
        //获取认证信息
        String authorization = authInfo.getAuthorization();

        //构造请求
        HttpPost method = null;
        try {
            method = new HttpPost(url);
            method.setHeader("Date", date);
            method.setHeader("Authorization", authorization);
            method.setHeader("AuthVersion", "2");
            if (ciphertext != null) {
                //加密之后data通过http body传输
                StringEntity stringEntity = new StringEntity(ciphertext, Consts.UTF_8);
                stringEntity.setContentEncoding("UTF-8");
                stringEntity.setContentType("application/json");
                method.setEntity(stringEntity);
            }
            CustomConfiguration.setString("http.connection.socket.timeout", "50000");
            StringResponse response = HttpUtil.post(method);
            System.out.println("rslt:" + response.getResponseBody());
        } finally {
            if (method != null) {
                method.releaseConnection();
            }
        }


    }
}
